local steam__zhuquan = fk.CreateSkill {
  name = "steam__zhuquan",
}

Fk:loadTranslationTable{
  ["steam__zhuquan"] = "诛权",
  [":steam__zhuquan"] = "每回合限一次，你可以视为使用或打出一张【杀】并令对方不可以：①<a href='steam__zhuquan-prodiscard'>弃置牌</a>；②打出牌。直至有角色执行另一项或其进入濒死。",

  ["#steam__zhuquan"] = "诛权：你可以视为使用或打出一张【杀】，令对方不能执行其中一项直到其进入濒死或执行另一项",
  ["#steam__zhuquan-discard"] = "诛权：你不能弃置牌",
  ["#steam__zhuquan-respond"] = "诛权：你不能打出牌",
  ["@steam__zhuquan"] = "诛权",
  ["steam__zhuquan-prodiscard"]="不能从手牌中选择牌弃置",
  ["zhuquan_prohibit_discard"]="目前不能弃置牌",
  ["zhuquan_prohibit_respond"]="目标不能打出牌",
  ["@@zhuquan_prohibit_discard"]="不能弃置",
  ["@@zhuquan_prohibit_respond"]="不能打出",

  ["$steam__zhuquan1"] = "诸葛小子，树大招风啊。",
  ["$steam__zhuquan2"] = "从弟嚣逆，我自谋诛。",

  ["#steam__zhuquan"]="诛权：你可以视为使用或打出一张【杀】",
}
local U = require "packages/utility/utility"

steam__zhuquan:addEffect("viewas",{
  pattern = "slash",
  prompt = "#steam__zhuquan",
  interaction = function(self, player)
    local all_names = {"slash"}
    local names = player:getViewAsCardNames(steam__zhuquan.name, all_names)
    if #names > 0 then
      return UI.CardNameBox {choices = names, all_choices = all_names}
    end
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self)
    if not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = steam__zhuquan.name
    return card
  end,
  after_use = function(self, player, use)
    local room=player.room
    
    local choices={"zhuquan_prohibit_discard","zhuquan_prohibit_respond"}
    local ch=room:askToChoice(player,{
      choices = choices,
      skill_name = "steam__zhuquan",
    })

    if use.tos then
      for _,p in ipairs(use.tos) do
        room:setPlayerMark(p, "@@"..ch, 1)--标记
      end
    end
    
    if use.responseToEvent then
      local to
    
      if use.responseToEvent.from == player then
        to = use.responseToEvent.to  -- duel used by zhaoyun
      else
        to = use.responseToEvent.from  -- savage_assault, archery_attack, passive duel
        -- TODO: Lenovo shu zhaoyun may chongzhen liubei when responding to jijiang
      end
      if to and not to.dead then
          room:setPlayerMark(to, "@@"..ch, 1)--标记
      end
    end

  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(steam__zhuquan.name, Player.HistoryTurn) == 0
  end,
  enabled_at_response = function(self, player, response)
    return player:usedSkillTimes(steam__zhuquan.name, Player.HistoryTurn) == 0 

  end,
})


steam__zhuquan:addEffect("prohibit",{
  prohibit_discard = function(self, player, card)
      return table.contains(player:getCardIds("h"), card.id) and player:getMark("@@zhuquan_prohibit_discard")>0
  end,
  prohibit_response = function(self, player, card)
    return player:getMark("@@zhuquan_prohibit_respond")>0
  end,
})

--有人弃牌，解除打牌标记
steam__zhuquan:addEffect(fk.AfterCardsMove, {
  can_refresh = function(self, event, target, player, data)
    if not player:hasSkill(steam__zhuquan.name) then return end
    if table.find(player.room.alive_players,function (p)
      return p:getMark("@@zhuquan_prohibit_respond")>0
    end) then
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard then
        return  true
      end
    end
  end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _,p in ipairs(room.alive_players) do
      if p:getMark("@@zhuquan_prohibit_respond")>0 then
        room:setPlayerMark(p, "@@zhuquan_prohibit_respond", 0)--标记
      end
    end
  end,
})

steam__zhuquan:addEffect(fk.CardRespondFinished, {
  can_refresh = function(self, event, target, player, data)
    return target:getMark("@@zhuquan_prohibit_discard")>0 and player:hasSkill(steam__zhuquan.name)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(target, "@@zhuquan_prohibit_discard", 0)--标记归0
  end,
})

--进入濒死时
steam__zhuquan:addEffect(fk.EnterDying, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(steam__zhuquan.name)
    and (target:getMark("@@zhuquan_prohibit_respond")>0 or target:getMark("@@zhuquan_prohibit_discard")>0)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(target, "@@zhuquan_prohibit_respond", 0)--标记归0
    room:setPlayerMark(target, "@@zhuquan_prohibit_discard", 0)--标记归0
  end,
})





return steam__zhuquan
